#include <iostream>
#include <string.h>
using namespace std;
int main()
{
	int n;
	while(cin>>n){
		for(int i=1;i<=n;i++){
			int a,b;
			int fenshu=1000;
			int re[4];
			memset(re,0,sizeof(re));
			for(int j=0;j<4;j++){
				cin>>a>>b;
				if(fenshu*(250-a)/250>=fenshu*40/100){
					re[j]=re[j]+fenshu*(250-a)/250;
				}
				else{
					re[j]=fenshu*40/100;
					fenshu=fenshu+500;
					continue;
				}
				if(re[j]-50*b>=fenshu*40/100){
					re[j]=re[j]-50*b;
				}
				else{
					re[j]=fenshu*40/100;
				}
				fenshu=fenshu+500;
			}
			cout<<"Case #"<<i<<": "<<re[0]+re[1]+re[2]+re[3]<<endl;
		}
	
	}
}
